<template>
  <div class="newCD">
    <div class="v-hd2">
      <router-link to="/home/album" class="new">新碟上架</router-link>
      <span class="more">
        <a href="#" class="s-fc3">更多</a>
        <i class="cor">&nbsp;</i>
      </span>
    </div>
    <div class="inner">
      <a href="javascript:;" class="left_btn" @mousedown="last">&nbsp;</a>
      <a href="javascript:;" class="right_btn" @mousedown="next">&nbsp;</a>
      <div class="roll f-pr" >
        <ul
          class="f-cb myul"
          :style="[{ left: w_item.type }]"
          v-for="(w_item, w_index) in item_style"
          :key="w_index"
          ref="ul"
        >
          <li v-for="(item, i) in w_item.item_data" :key="i">
            <div class="u-cover-alb1">
              <a
                class="u-cover"
                :title="item.name"
                @click.stop="toalbum(item.id)"
                
              >
                <img :src="item.picUrl+'?param=100y100'">
                <a href="javascript:;" class="play" @click.stop="send_Album(item.id, $event)"></a>
              </a>
              <p class="f-thide tit">{{ item.name }}</p>
              <p class="f-thide"></p>
            </div> 
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import { album_newest } from "../../../network/discover";

export default {
  data() {
    return {
      item_style: [
        { type: "-650px",item_data:null},
        { type: "0", item_data:null},
        { type: "650px", item_data:null},
        { type: "1300px",item_data:null},
      ],
      // item_data:[],
      flag:true,
      num: 1,
      icon_flag: null,
      moing: true,
    };
  },
  methods: {
    toalbum(id){
      this.$router.push({path:'/home/album' , query:{id:id}})
    },
     send_Album(album_id, e) {  //播放专辑
      this.$store.dispatch("album_ct", { album_id: album_id, pageY: e.pageY });
    },
    next() {
      //下一轮
        if(this.flag){
            var that = this
            this.flag = false
            var nextId = this.num+ 1 > that.item_style.length-1  ? 0 : this.num+1
            this.$refs.ul[this.num].style.left = '-650px'
            this.$refs.ul[nextId].style.left  = '0px'
            this.$refs.ul[this.num].style.transition = this.$refs.ul[nextId].style.transition = 'left 1s ease-out 0s'
            
            this.$refs.ul[nextId].ontransitionend = function(){
            that.$refs.ul[that.num].style.transition =  that.$refs.ul[nextId].style.transition = 'none 0s ease 0s'
            that.num = nextId
            let cnm =  nextId +1 > that.item_style.length-1  ? 0 : nextId+1
            that.$refs.ul[cnm].style.left = '650px'
            that.flag = true
            this.ontransitionend = null
          }
        }
    },
   
    last() {
      //上一轮
      if(this.flag){
         var that = this
         this.flag = false
          var nextId = this.num -1 < 0 ? this.item_style.length -1 : this.num - 1;
          this.$refs.ul[this.num].style.left = '650px'
          this.$refs.ul[nextId].style.left = '0px'
          this.$refs.ul[this.num].style.transition = this.$refs.ul[nextId].style.transition = 'left 1s ease-out 0s'
        
        this.$refs.ul[nextId].ontransitionend = function(){
              that.$refs.ul[that.num].style.transition =  that.$refs.ul[nextId].style.transition = 'none 0s ease 0s'
               that.num = nextId
               let Nnext =  nextId-1 < 0 ? that.item_style.length -1 :  nextId- 1;
              that.$refs.ul[Nnext].style.left = '-650px'
              that.flag = true
              this.ontransitionend = null
          }
      }
    },
  },
  created() {
    album_newest().then((res) => {
     this.item_style[0].item_data =  this.item_style[2].item_data = res.data.albums.slice(0 , 5)
     this.item_style[1].item_data =  this.item_style[3].item_data = res.data.albums.slice(5 , 10)
    })
  },
};
</script>

<style  scoped>
.newCD {
  display: block;
}
.v-hd2 {
  height: 33px;
  padding: 0 10px 0 34px;
  border-bottom: 2px solid #c10d0c;
  background: url("../../../assets/imgs/index.png") no-repeat;
  background-position: -225px -156px;
}
.new {
  display: block;
  line-height: 28px;
  font-weight: normal;
  font-size: 20px;
  float: left;
}
.more {
  float: right;
  margin-top: 9px;
}
.more a {
  color: #666;
  font-size: 12px;
}
.cor {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 4px;
  vertical-align: middle;
  background: url("../../../assets/imgs/index.png") no-repeat;
  background-position: 0 -240px;
}
.inner {
  height: 182px;
  border: 1px solid rgb(211, 211, 211);
  margin: 20px 0px 37px;
  background: rgb(245, 245, 245);
  padding-left: 16px;
  position: relative; 
}
.left_btn,
.right_btn {
  position: absolute;
  display: block;
  width: 16px;
  height: 16px;
}
.left_btn {
  top: 73px;
  left: 0;
  background: url("../../../assets/imgs/index.png") no-repeat;
  background-position: -263px -75px;
}
.right_btn {
  top: 74px;
  right: 0px;
  background: url("../../../assets/imgs/index.png") no-repeat;
  background-position: -302px -75px;
}
.inner ul {
  width: 650px;
  position: absolute;
  top: 0;
  margin-right: 1px;
  padding-top: 26px;
}
.f-cb::after {
  clear: both;
  content: ".";
  display: block;
  height: 0;
  visibility: hidden;
}
.f-cb li {
  width: 119px;
  height: 150px;
  margin-left: 11px;
  float: left;
  background: url("../../../assets/imgs/index.png") no-repeat;
  background-position: -260px 101px;
}
.f-cb .u-cover-alb1 {
  width: 100%;
  height: 100%;
  position: relative;
}
.f-cb .u-cover {
  width: 100%;
  height: 72%;
  display: block;
  background: url("../../../assets/imgs/coverall.png") no-repeat;
  background-position: 0 -570px;
}
.f-cb .u-cover img {
  width: 85%;
  height: 94%;
}
.f-cb .u-cover .play {
  width: 22px;
  height: 22px;
  position: absolute;
  top: 78px;
  left: 75px;
  background: url("../../../assets/imgs/iconall.png") no-repeat;
  background-position: 0 -85px;
  display: block;
}
.f-cb .u-cover .play:hover {
  background-position: 0 -110px;
}

.f-cb .f-thide {
  font-size: 12px;
  color: #666;
  white-space: nowrap;
  word-wrap: normal;
  line-height: 18px;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0px;
}
.f-cb .tit {
  margin-top: 5px;
  color: black;
  font-family: Arial, Helvetica, sans-serif;
}
.f-cb p:hover {
  text-decoration: underline 1px;
  cursor: pointer;
}
.inner .roll {
  float: left;
  width: 650px;
  height: 180px;
  overflow: hidden;
}
</style>